<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
  <link href="perl.css" rel="stylesheet" type="text/css">
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  <title>Pugs Apocryphon 1</title>
  <meta content="Audrey Tang" name="author">
</head>
<body>
<h1 style="text-align: left; line-height: normal;" align="left">
Pugs
Apocryphon 1<br>
<span style="font-weight: normal;">Overview
of the Pugs project</span></h1>
<h2>
What is this document about?</h2>
<p>
The <a href="http://svn.perl.org/perl6/pugs/trunk/docs/">Pugs
Apocrypha</a>
are a series of documents, written in question/answer format, to
explain the
design and implementation of Pugs. This document (PA01) is a
higher-level
overview of the project.</p>
<h2>
What is Pugs?</h2>
<p>
Started in February 2005, <a href="http://pugscode.org/">Pugs</a>
is an implementation of the Perl 6
language. <a href="http://use.perl.org/%7Eautrijus/journal/">Autrijus
Tang</a> is responsible for the
design and development of Pugs with help from a group of committers and
contributors.</p>
<h2>
What is Perl 6?</h2>
<p>
<a href="http://dev.perl.org/perl6/">Perl
6</a>
is the next major revision of Perl, a context-sensitive,
multi-paradigmatic, <i>practical</i>
programming language, designed by a team led by Larry Wall. The Pugs
project
has been <a
 href="http://www.nntp.perl.org/group/perl.perl6.language/19263">enthusiastically
welcomed</a> by the Perl 6 team.</p>
<h2>
Has Perl 6 been specified?</h2>
<p>
By December 2004, most of Perl 6 had
been
specified as a series of <a href="http://dev.perl.org/perl6/synopsis/">Synopses</a>.
Although not considered final, it is now stable enough to be
implemented. Many
of the Synopses are based on Larry's <a
 href="http://dev.perl.org/perl6/apocalypse/">Apocalypses</a>.
Sometimes the
design team releases <a href="http://dev.perl.org/perl6/exegesis/">Exegeses</a>,
which explain the meaning of Apocalypses. Pugs adheres to
the Synopses, referring to Apocalypses or
Exegeses when a Synopsis is unclear or imprecise.</p>
<h2>
What does
&ldquo;Apocrypha&rdquo; mean?</h2>
<p>
The word <a href="http://en.wikipedia.org/wiki/Apocrypha">Apocrypha</a>,
from the Greek
&alpha;&pi;ό&kappa;&rho;&upsilon;&phi;&omicron;&sigmaf;,
&ldquo;hidden&rdquo;, refers to religious works that are not
considered
canonical, or part of officially accepted scripture. The proper
singular form
in Greek is <i>Apocryphon</i>.</p>
<h2>
What is the relationship between
Apocrypha and the Perl 6
design documents?</h2>
<p>
Apocalypses and Synopses cover the Perl
6
language in general; Apocrypha are specific to the Pugs implementation.
Like <a href="http://www.parrotcode.org/docs/pdd/">Parrot
Design Documents</a>, Apocrypha
will be constantly updated according to the status of Pugs.</p>
<h2>
Will Pugs implement the full Perl 6
specification?</h2>
<p>
Yes. Pugs always targets the latest
revision of Perl 6 Synopses. As soon as a new revision or a new
Synopsis is published,
incompatibilities between Pugs and the new version will be considered
bugs in
Pugs.</p>
<h2>
Is Pugs free software?</h2>
<p>
Yes. It is available under both <a
 href="http://svn.openfoundry.org/pugs/LICENSE/GPL-2">GPL
version 2</a> and <a
 href="http://svn.openfoundry.org/pugs/LICENSE/Artistic-2">Artistic
License
version 2.0b5</a>. Once the final
version of Artistic 2.0 is released, Pugs
will adopt it.</p>
<h2>
Is Pugs funded by the Perl Foundation?</h2>
<p>
No. After receiving three <a
 href="http://www.perlfoundation.org/gc/grants/2003_autrijus.html">Perl
Foundation grants</a> on various
projects, Autrijus decides it would be more
helpful to donate time to the Perl 6 project by hacking Pugs, rather
than
asking TPF for money to do the same thing.</p>
<h2>
Where can I download Pugs?</h2>
<p>
For the very latest version of Pugs,
check
out the source from <a href="http://svn.openfoundry.org/pugs/">Subversion</a>
or <a href="http://wagner.elixus.org/%7Eautrijus/darcs/pugs">darcs</a>
repositories. Periodic releases are available on CPAN
under the <a href="http://search.cpan.org/dist/Perl6-Pugs/">Perl6-Pugs</a>
namespace.
(By the way, if you'd like offline working with the Subversion
repository, the <a href="http://svk.elixus.org/">svk</a>
client may be of interest. But using
vanilla svn is fine.)</p>
<h2>
How do I build Pugs?</h2>
<p>
Pugs uses the standard Makefile.PL build
system, as detailed in the <a
 href="http://svn.openfoundry.org/pugs/README"><code>README</code></a>
file. Since Pugs is written in Haskell, you will need <a
 href="http://haskell.org/ghc/">Glasgow Haskell
Compiler</a> (GHC) 6.4 or above.
Please download a <a href="http://haskell.org/ghc/">binary build</a>
for your
platform; compiling GHC from source code can take a very long time.</p>
<h2>
What is Haskell?</h2>
<p>
<a href="http://haskell.org/">Haskell</a>
is a standardized, purely functional programming language with
built-in <a href="http://en.wikipedia.org/wiki/Lazy_evaluation">lazy
evaluation</a>
capabilities. While there are several different implementations
available,
currently Pugs needs to be built with GHC, because it uses several
GHC-specific
features.</p>
<h2>
What is GHC?</h2>
<p>
GHC is a state-of-the-art compiler and
interactive
environment, available under a <a
 href="http://haskell.org/ghc/license.html">BSD-style
license</a>. Itself written in
Haskell, GHC can compile Haskell to bytecode, C
code, and machine code on some platforms. GHC has an extensive library,
numerous language extensions, and a very capable optimizer (with some
help from
a <a
 href="http://www.cse.unsw.edu.au/%7Echak/haskell/ghc/comm/the-beast/mangler.html">Perl
5 program</a>). As such, it provides
an excellent platform to solve Perl 6&rsquo;s <i>bootstrapping
problem</i>.</p>
<h2>
What is the Perl 6 bootstrapping problem?</h2>
<p>
The goal of the Perl 6 project is to be <i>self-hosting</i>:
The Perl 6 compiler needs to be written in Perl 6 itself, and must
parse Perl 6
source code with Perl 6 Rules, which is a subset of the Perl 6
language. The
generated code must also contain an evaluator that can execute Perl 6
code on
the fly. The only way to break this cycle of dependency is by first
implementing some parts in other languages, then rewrite those parts in
Perl 6.</p>
<h2>
What was the initial bootstrapping plan?</h2>
<p>
According to the <a
 href="http://search.cpan.org/dist/parrot/docs/faq.pod#Isn%27t_there_a_bootstrapping_problem?">Parrot
FAQ</a>, the initial plan was to
bootstrap via Perl 5: First we extend Perl 5
to run on the Parrot virtual machine (via <code>B::Parrot</code>
or <a href="http://www.poniecode.org/">Ponie</a>),
and then implement the Perl 6
compiler in Perl 5, which will be translated to Perl 6 via a p5-to-p6
translator. However, although part of the Rule system was prototyped in
Perl 5
as <a
 href="http://search.cpan.org/dist/Perl6-Rules/"><code>Perl6::Rules</code></a>,
it was not mature enough to build a compiler on. As such, the plan was revised
to bootstrap via C instead.</p>
<h2>
What was the revised bootstrapping plan?</h2>
<p>
According to an early 2005 <a
 href="http://www.perlfoundation.org/gc/grants/2005-p6-proposal.html">proposal</a>,
the plan is to first implement the Rule engine in C (i.e. <a
 href="http://svn.perl.org/viewcvs/parrot/trunk/compilers/pge/">PGE</a>),
use it to parse Perl 6 into Parrot as an <a
 href="http://en.wikipedia.org/wiki/Abstract_syntax_tree">abstract
syntax tree</a>
(AST), and then implement an AST evaluator as part of Parrot. Ponie and
p5-to-p6 are still in progress, but they are no longer critical
dependencies in
the
bootstrapping process.</p>
<h2>
How can Pugs help Perl 6 to bootstrap?</h2>
<p>
In a bootstrapping process, there are
often
many bottlenecks, which prevent people from working on things that
depend on
them. For example, one cannot easily write unit tests and standard
libraries
for Perl 6 without a working Perl 6 implementation, or work on an AST
evaluator
without an AST interface. Pugs solves such deadlocks by providing ready
substitutes
at various levels of the process.</p>
<h2>
How can Pugs help the Perl 6 language
design?</h2>
<p>
Without a working implementation, it is very hard to spot
inconsistencies and corner cases in the specification.
However,
if a design problem is found late into the implementation, it may
require
costly re-architecture for everything else. By providing a working Perl
6
implementation, Pugs can serve as a proving ground to resolve problems
as early
as possible, as well as encourage more people to exercise Perl
6&rsquo;s features.</p>
<h2>
Why did you choose Haskell?</h2>
<p>
Many Perl 6 features have similar
counterparts in Haskell: Perl 6 Rules corresponds closely to <a
 href="http://www.cs.uu.nl/%7Edaan/download/parsec/parsec.html">Parsec</a>;
lazy
list evaluation is common in both languages; continuation support can
be
modeled with the <a
 href="http://www.nomaware.com/monads/html/contmonad.html">ContT</a>
monad transformer, and so on. This greatly simplified the prototyping
effort:
the first working interpreter was released within the <a
 href="http://use.perl.org/%7Eautrijus/journal/23051">first
week</a>, and by the <a
 href="http://use.perl.org/%7Eautrijus/journal/23335">third
week</a> we had a full-fledged <a
 href="http://svn.openfoundry.org/pugs/ext/Test/lib/Test.pm"><code>Test.pm</code></a>
module for unit testing.</p>
<h2>
Is Pugs a compiler or an interpreter?</h2>
<p>
Similar to Perl 5, Pugs first compiles
Perl
6 program to an AST, then executes it using the built-in evaluator.
However, in
the future Pugs may also provide a compiler interface that supports
different
compiler backends.</p>
<h2>
Which compiler backends do you have in
mind?</h2>
<p>
If implemented, the first compiler
backend
will likely generate Perl 6 code, similar to the <a
 href="http://search.cpan.org/dist/perl/ext/B/B/Deparse.pm"><code>B::Deparse</code></a>
module. The next one may generate
Haskell code, which can then be
compiled to C by GHC. At that point, it may make sense to target the <a
 href="http://svn.perl.org/viewcvs/parrot/trunk/compilers/ast/">Parrot
AST</a>
interface. We can also add other backends (such as Perl 5 bytecode) if
people
are willing to work on them.</p>
<h2>
Do you have a roadmap for Pugs
development?</h2>
<p>
The major/minor version numbers of Pugs
converges to 2*&pi;; each significant digit in the minor version
represents a
milestone. The third digit is incremented for each release. The current
milestones are:</p>
<ul>
  <li>6.0: Initial release.</li>
  <li>6.2: Basic IO and control
flow
elements; mutable variables; assignment.</li>
  <li>6.28: Classes and traits.</li>
  <li>6.283: Rules and Grammars.</li>
  <li>6.2831: Type system and linking.</li>
  <li>6.28318: Macros.</li>
  <li>6.283185: Port Pugs to
Perl 6,
if
needed.</li>
</ul>
<h2>
How portable is Pugs?</h2>
<p>
Pugs runs on Win32, Linux and many
flavors
of Unix systems. See GHC&rsquo;s <a
 href="http://haskell.org/ghc/contributors.html">porters
list</a> and <a href="http://haskell.org/ghc/download_ghc_622.html">download
page</a> for details. Starting from
6.2.0, the Pugs team will also provide
binary builds on selected platforms.</p>
<h2>
How fast is Pugs?</h2>
<p>
The parser part of Pugs is very fast,
due
to its robust underpinning in Parsec. However, the Pugs evaluator is
currently
not optimized at all: dispatching is around 1000 operators per second
on a
typical PC, which is nearly 100 times slower than Perl 5. Still, it is
fast
enough for prototyping language features; if you need fast operations
in Pugs,
please consider helping out the Compiler backend.</p>
<h2>
Is there a CPAN for Perl 6 modules?</h2>
<p>
No. The current preferred method for submitting Perl 6/Pugs modules is to
ask for a committer bit at openfoundry.org and to add your module to the 
Pugs source tree under the modules/ directory. It is also helpful to include 
test suites with your modules as well, so we can know when they work.
</P>
<P>
However, all is not lost. If you are patient you can wait for 
<code>Pugs::MakeMaker</code> and <code>Module::Install::Pugs</code> to come out
on CPAN. Once they are available individually on CPAN, you can begin submitting
things to CPAN, because that means we've figured out the distribution problem.
Of course, suggestions are always welcome.
</p>
<h2>
Can Pugs work with Perl 5 libraries?</h2>
<p>
Yes, Pugs can work with Perl 5 libraries.  This requires that Pugs be
compiled with Perl 5 embedding.  Pugs understands Perl 5 objects, classes
and functions.  Pugs objects, classes and functions are also understood by
Perl 5.  As such, these types can be used in round-trip callbacks.</p>

<p>Examples of working with Perl 5 may be found <a href="http://svn.openfoundry.org/pugs/t/unspecced/p5/">in the source
tree</a>.
<h2>
Can Pugs work with Haskell libraries?</h2>
<p>Pugs can be compiled with <a
href="http://www.cse.unsw.edu.au/%7Edons/hs-plugins/"><code>hs-plugins</code></a>
 support, which allows it to use Haskell libraries.  It is also capable of
 dynamically loading Haskell modules.  Aside from this, inline Haskell can
 be evaluated using <code>eval('...', :lang&lt;haskell&gt;)</code>.</p>
<p>In addition, at the basic level, you can statically link Haskell libraries
into Pugs primitives, by modifying a few lines in <a
 href="http://svn.openfoundry.org/pugs/src/Pugs/Prim.hs"><code>Prim.hs</code></a>.
</p>
<h2>
Can Pugs work with C libraries?</h2>
<p>
Not yet. However, <a href="http://www.haskell.org/hdirect/">HaskellDirect</a>
seems to provide an
easy way to interface with C, CORBA and COM libraries, especially when
combined
with hs-plugins described above.</p>
<h2>
I know Perl 5, but not Haskell. Can I
develop Pugs?</h2>
<p>
Sure! The standard libraries and unit
tests
that come with Pugs are coded in Perl 6, and there is always a need for
more
tests and libraries. All you need is basic familiarity of Perl 5, and a
few
minutes to get acquainted with some small syntax changes. You will
likely pick
up some Haskell knowledge along the way, too.</p>
<h2>
I know Haskell, but not Perl 5. Can I
develop Pugs?</h2>
<p>
Sure! Perl 6 and Haskell have many
things
in common, such as type-based function dispatch, first class functions
and
currying, so picking up the syntax is relatively easy. Since there are
always
some TODO tests for features in need of implementation, it is never
hard to
find something to do.</p>
<h2>
I have learned some Perl 6. What can I
do with Pugs?</h2>
<p>
Look at the examples/ directory to see
some
sample programs. Some people are already writing web applications and
report
systems with Pugs. If you run into a missing feature in Pugs, please
let us
know so we can implement it.</p>
<h2>
Where can I learn more about Haskell?</h2>
<p>
The <a href="http://www.haskell.org/">Haskell
homepage</a> and the <a href="http://haskell.org/hawiki/">Wiki</a>
are good
entry points. Of the many online tutorials, <a
 href="http://www.isi.edu/%7Ehdaume/htut/">Yet Another
Haskell Tutorial</a> is
perhaps the most accessible. Due to the ubiquitous use of Monad
transformers in
Pugs, <a href="http://www.nomaware.com/monads/html/">All About
Monads</a> is
also recommended. For books, <a
 href="http://www.iro.umontreal.ca/%7Elapalme/Algorithms-functional.html">Algorithms:
A Functional Programming Approach</a>,
<a href="http://www.cs.kent.ac.uk/people/staff/sjt/craft2e/">Haskell:
The Craft of
Functional Programming</a> and <a href="http://haskell.org/soe/">The
Haskell School of
Expression</a>
are
fine introductory materials. Finally, the
<a href="irc://irc.freenode.net/haskell"><code>#haskell</code> channel</a> on
<a href="http://freenode.net/">irc.freenode.net</a> is full of helpful and
 interesting people.</p>
<h2>
Where can I learn more about Perl 6?</h2>
<p>
The <a href="http://dev.perl.org/perl6/">Perl
6 homepage</a> provides many online
documents. Every week or two, a new Perl 6
list summary will appear on <a href="http://www.perl.com/">Perl.com</a>;
it is
a must-read for people who wish to follow Perl 6&rsquo;s progress.
For books, <a href="http://www.oreilly.com/catalog/059600737X/">Perl
6 and Parrot Essentials</a>
and <a href="http://www.apress.com/book/bookDisplay.html?bID=355">Perl
6 Now</a>
are both helpful.</p>
<h2>
Where can I learn more about
implementing programming
languages?</h2>
<p>
<a href="http://www.cis.upenn.edu/%7Ebcpierce/tapl/">Types
and Programming Languages</a>
is an essential read; Pugs started out as a self-initiated study of the
text,
and it continues to be an important guide during the implementation.
Its
sequel, <a href="http://www.cis.upenn.edu/%7Ebcpierce/attapl/">Advanced
Topics in
Types and Programming Languages</a>,
is also invaluable. It may also help to
get acquainted with other multi-paradigmatic languages, such as <a
 href="http://www.mozart-oz.org/">Mozart/Oz</a>,
<a href="http://www.informatik.uni-kiel.de/%7Emh/curry/">Curry</a>
and <a href="http://www.ocaml.org/">O&rsquo;Caml</a>.
Finally, the detailed <a
 href="http://www.cse.unsw.edu.au/%7Echak/haskell/ghc/comm/">GHC
commentary</a>
describes how GHC itself was implemented.</p>
<h2>
I&rsquo;d like to help. What should
I do?</h2>
<p>
First, subscribe to the <a
 href="http://nntp.perl.org/group/perl.perl6.compiler">perl6-compiler</a>
mailing list by sending an empty mail to <a
href="mailto:perl6-compiler-subscribe@perl.org">perl6-compiler-subscribe@perl.org</a>.
Next, join the <a href="irc://irc.freenode.net/perl6"><code>#perl6</code>
IRC channel</a> on <a href="http://freenode.net/">irc.freenode.net</a> to find out what needs to be done. Commit
access is handed out liberally; contact the Pugs team on <code>#perl6</code>
for details. See you on IRC!</p>
</body>
</html>
